import  urllib.request as ur
import  urllib.parse as up
import json

#循环输入
while True:
    word = (input('请输入要翻译的内容')).strip()
    data = {
        'kw':word,
    }
    #url 编码
    data_url = up.urlencode(data)
    request = ur.Request(
        url = 'https://fanyi.baidu.com/sug',
        method='POST',
        data = data_url.encode('utf-8'),
        unverifiable=True
    )
    response = ur.urlopen(request).read()
    # print(type(response))
    ret = json.loads(response)
    # print(ret)
    try:
        data_s = ret['data']
        for data in data_s:
            print(data['k'],data['v'])
    except:
        print('未查到相关结果，请规范您的输入！')
    print('='*60)